<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateQuestionsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('questions', function (Blueprint $table) {
            $table->id()->index();
            $table->unsignedBigInteger('user_id')->comment('创建人')->index();
            $table->unsignedBigInteger('category_id')->comment('所属分类')->index();
            $table->string('type', 12)->comment('题目类型（单选，多选等）')->index();
            $table->string('title')->comment('标题')->index();
            $table->text('content')->comment('题干');
            $table->json('answer')->nullable()->comment('答案选项');
            $table->text('success_answer')->comment('正确答案');
            $table->tinyInteger('status')->default(0)->comment('审核状态(0:未审核，1:审核)')->index();
            $table->integer('fraction')->comment('分数（作为随机题目时 不生效）');
            $table->integer('num')->default(0)->comment('使用次数');
            $table->integer('success_num')->default(0)->comment('正确次数');
            $table->integer('error_num')->default(0)->comment('错误次数');
            $table->integer('level')->default(1)->comment('试题难度（1-3）星')->index();
            $table->text('analysis')->nullable()->comment('答案解析');
            $table->integer('order')->default(0)->comment('排序')->index();
            $table->integer('pid')->nullable()->comment('父级题目ID (子母题)')->index();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('questions');
    }
}
